package com.ktjy.test;

import com.ktjy.entity.SysUser;
import com.ktjy.service.SysUserService;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Arrays;
import java.util.List;

/**
 * @author 黄军艳
 * @version 1.0
 * @date 2024/12/9  8:40
 */
public class Main {
    Logger logger= LoggerFactory.getLogger(Main.class);
    @Test
    public void test1() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        SysUserService userService=(SysUserService)context.getBean("sysUserService");
        //构建查询条件
        SysUser queryCondition=new SysUser();
        queryCondition.setRealName("李");
        queryCondition.setRoleId(3l);
        List<SysUser> userList=userService.getSysUserList(queryCondition);
        for(SysUser user:userList){
            logger.info("SysUser: account={}, realName={}, roleName={}",
                    user.getAccount(), user.getRealName(),
                    user.getSysRole().getRoleName());
        }
    }

    @Test
    public void test2() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        SysUserService userService=(SysUserService)context.getBean("sysUserService");
        SysUser user1=new SysUser();
        user1.setRealName("测试用户1");
        user1.setAccount("ceshi1");
        SysUser user2=new SysUser();
        user2.setRealName("测试用户2");
        user2.setAccount("ceshi2");
        List<SysUser> userList= Arrays.asList(user1,user2);
        userService.saveBatch(userList);
    }
}
